from pptx import Presentation
from pptx.util import Inches
from pptx.enum.shapes import MSO_SHAPE
from pptx.dml.color import RGBColor

# 创建演示文稿对象
prs = Presentation()

# 添加一张空白幻灯片
slide_layout = prs.slide_layouts[5]  # 空白布局
slide = prs.slides.add_slide(slide_layout)

# 添加一个形状
shape = slide.shapes.add_shape(
    MSO_SHAPE.RECTANGLE, Inches(1), Inches(1), Inches(4), Inches(2)
)

# 访问阴影格式
shadow = shape.shadow
print(f"Shadow format object: {shadow}")
print(f"Shadow format type: {type(shadow)}")
print(f"Shadow format attributes: {dir(shadow)}")

# 尝试设置阴影颜色的不同方法
try:
    shadow.fore_color.rgb = RGBColor(150, 150, 150)
    print("Set shadow.fore_color.rgb succeeded")
except AttributeError as e:
    print(f"Error setting shadow.fore_color.rgb: {e}")

try:
    shadow.color.rgb = RGBColor(150, 150, 150)
    print("Set shadow.color.rgb succeeded")
except AttributeError as e:
    print(f"Error setting shadow.color.rgb: {e}")

try:
    shadow.fill.fore_color.rgb = RGBColor(150, 150, 150)
    print("Set shadow.fill.fore_color.rgb succeeded")
except AttributeError as e:
    print(f"Error setting shadow.fill.fore_color.rgb: {e}")

# 保存演示文稿\pprs.save('shadow_test.pptx')
print("Presentation saved as 'shadow_test.pptx'")